import axios from 'axios'
import { baseUrl } from '@/config/config'
// 添加响应拦截
import interceptors from './interceptors'
// 在vue内直接使用http包含api地址
export const http = axios.create({
  baseURL: baseUrl
})
// 设置ticket授权
export function setTicket (ticket) {
  // http.defaults.headers.common.Authorization = `${ticket}`
}
/* eslint-disable space-before-function-paren */
// vue http 请求插件,方便可以全局调用
export default function install(Vue, { store, router }) {
  interceptors(http, store, router)
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
  Object.defineProperty(Vue.prototype, '$http', {
    get() {
      return http
    }
  })
}
